#if !defined(HRX_H_INCLUDED)
#define HRX_H_INCLUDED

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

class HRX
{
public:
	explicit HRX(HRESULT hr = S_OK) : m_hr(hr) { if( FAILED(hr) ) throw hr; }
	HRX &operator=(HRESULT hr) { m_hr = hr; if( FAILED(hr) ) throw hr; return *this; }
	operator HRESULT () { return m_hr; }
	
protected:
	HRESULT m_hr;
};

class HRX2 : public HRX
{
public:
	HRX2(HRESULT hrSuccessCondition, HRESULT hr = S_OK, HRX *pHRX = NULL) : m_pHRX(pHRX), m_hrSuccessCondition(hrSuccessCondition)
	{ if(m_pHRX) (*m_pHRX) = hr; m_hr = hr; if( !m_hrSuccessCondition & hr ) throw hr; }

	HRX2 &operator= (HRESULT hr)
	{ if(m_pHRX) (*m_pHRX) = hr; m_hr = hr; if( !m_hrSuccessCondition & hr ) throw hr; return *this; }

	operator HRESULT () { return m_hr; }

protected:
	HRESULT m_hrSuccessCondition;
	HRX *m_pHRX;
};

#endif	// #if !defined(HRX_H_INCLUDED)
